home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig05_33.jar / Ch05 / Fig05_33 / Fig05_33.cpp next >
C/C++ Source or Header  |  1997-10-14  |  454b  |  25 lines

  1. // Fig. 5.33: fig05_33.cpp
  2. // Using strtok
  3. #include <iostream.h>
  4. #include <string.h>
  5.  
  6. int main()
  7. {
  8.    char string[] = "This is a sentence with 7 tokens";
  9.    char *tokenPtr;
  10.  
  11.    cout << "The string to be tokenized is:\n" << string
  12.         << "\n\nThe tokens are:\n";
  13.  
  14.    tokenPtr = strtok( string, " " );
  15.  
  16.    while ( tokenPtr != NULL ) {
  17.       cout << tokenPtr << '\n';
  18.       tokenPtr = strtok( NULL, " " );
  19.    }
  20.  
  21.    return 0;
  22. }
  23.  
  24.  
  25.